package com.clever.mall.service.impl;

import com.clever.mall.entity.Category;
import com.clever.mall.mapper.CateGoryMapper;
import com.clever.mall.service.CateGoryService;
import com.clever.mall.utils.MyBeanUtils;
import com.clever.mall.vo.CateGoryVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CateGoryServiceImpl implements CateGoryService {
    @Resource
    CateGoryMapper cateGoryMapper;

    //查询热门分类前8条
    @Override
    public List<CateGoryVo> findHeatCateGory() {
        List<Category> categories = cateGoryMapper.selectHeatCategory();
        List<CateGoryVo> cateGoryVos = MyBeanUtils.copyListProperties(categories, CateGoryVo::new);
        return cateGoryVos;
    }

    //查询所有分类
    @Override
    public List<CateGoryVo> findAllCateGory() {
        List<Category> categories = cateGoryMapper.selectAllCategory();
        List<CateGoryVo> cateGoryVos = MyBeanUtils.copyListProperties(categories, CateGoryVo::new);
        return cateGoryVos;
    }

    //判断分类是否为一级分类
    @Override
    public boolean isFirst(Integer isFirst) {
        Integer integer = cateGoryMapper.selectUpIdById(isFirst);
        return integer==null;
    }
}
